package net.controller;

import net.pojo.Admin;
import net.service.AdminService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.DigestUtils;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("/mangager")
public class AdminController {
    @Autowired
    AdminService adminService;
    @RequestMapping("/adminlogin" )
    public String adminlogin(Admin admin, Model model, HttpSession session){
        Admin login = adminService.adminLogin(admin);
        if (login != null){
            if (!"超级用户".equals(login.getRole())){
                model.addAttribute("msg","你不是管理员，没有权限登录!");
                return "/admin/login/login.jsp";
            }else {
                session.setAttribute("admin",login);
                return "/admin/login/home.jsp";
            }
        }
        model.addAttribute("msg","用户名或密码错误!");
                return "/admin/login/login.jsp";



    }
}
